<?php
namespace Admin\Controller;

class CustomerController extends CommonController {

    public function login() {
        if (IS_POST) {
            $name = I("name", "", "trim");
            $pass = I("pass", "", "trim");
            if(empty($name) || empty($pass)) $this->error('用户名或者密码不能为空，请重新输入');
            
            if($customer = D('Customer')->where(array('username' => $name, 'password' => md5($pass)))->find()){
                if ($customer['status'] == '2') $this->error('您的账号已被系统关闭');
                session(C('ADMIN_SESSION'), $customer);
                $this->success(U('Admin/Index/index'));
            }else{
                $this->error('用户名或密码错误');
            }
        } else {
            $this->display();
        }
    }
    
    //退出操作
    public function logout(){
        session(C('ADMIN_SESSION'), null);
        redirect(U('Admin/Customer/login'));
    }

}